﻿using Common.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YunSpace.Application.OrderFlowManage;
using YunSpace.ThirdService;

namespace YunSpace.Services.Jobs.OrderFlow
{
    public class OrderCheckJob : IJob
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof(OrderCheckJob));

        public void Execute(IJobExecutionContext context)
        {
            try
            {
                CheckOrderJobApp OrderApp = new CheckOrderJobApp();
                var Items = OrderApp.GetItemList("CheckOrder");
                var Day = Items.First(t => t.Value == "PLZQ") == null ? "7" : Items.First(t => t.Value == "PLZQ").F_Description;
                var IsAgree= Items.First(t => t.Value == "RWZT") == null ? "0" : Items.First(t => t.Value == "RWZT").F_Description;
                if (IsAgree == "1")
                {
                    ClientOrderJobApp app = new ClientOrderJobApp();
                    RongLianSmsManger sms = new RongLianSmsManger();
                    var list= OrderApp.ExecuteCheckOrder(Day);
                    foreach (var item in list)
                    {
                        item.ManagerPhone.Add(item.F_MobilePhone);                        
                        string PhoneStr = String.Join(",", item.ManagerPhone);
                        string[] data = new string[] {item.F_Account+"("+item.F_RealName+")",item.F_ActivityTheme };
                        sms.SendCheckOrderInfo(PhoneStr,data);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("订单检查任务：更新定时任务异常！原因：{0}", ex);
            }
        }
    }
}
